#! /usr/bin/env python
from unittest import result
import rospy
import actionlib
from Decetion.msg import *
from CVbright import *

class MyActionServer:
    def __init__(self):
        #SimpleActionServer(name, ActionSpec, execute_cb=None, auto_start=True)
        self.server = actionlib.SimpleActionServer("decetion",ObjectAction,self.cb,False)
        self.server.start()
        rospy.loginfo("服务端启动")


    def cb(self,goal):
        rospy.loginfo("服务端被调用")
        
        imgros = goal.image
        img = imgmsg_to_cv2(imgros)

        # #2.循环累加，连续反馈
        # rate = rospy.Rate(10)
        # sum = 0
        # for i in range(1,num + 1):
        #     # 累加
        #     sum = sum + i
        #     # 计算进度并连续反馈
        #     feedBack = i / num
        #     rospy.loginfo("当前进度:%.2f",feedBack)

        #     feedBack_obj = peopleFeedback()
        #     feedBack_obj.progress_bar = feedBack
        #     self.server.publish_feedback(feedBack_obj)
        #     rate.sleep()

        result = ObjectResult()
        result.pick_object_x = 1.0
        result.pick_object_y = 1.0
        result.place_object_x = 2.0
        result.place_object_y = 2.0
        result.place_object_is_exist = True
        result.pick_object_is_exist = True
        result.reslut = "SUCCES"
 
        self.server.set_succeeded(result)
        rospy.loginfo("响应结果:%s",result.reslut)
        
if __name__ == "__main__":
    rospy.init_node("action_server_p")
    server = MyActionServer()
    rospy.spin()
